package com.sts.transform.function;

import com.googlecode.aviator.runtime.function.AbstractVariadicFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;

import java.util.Map;

/**
 * @author lsl
 * @since 2025年07月08日 19:32
 */
public class SeqEleFunction extends AbstractVariadicFunction {
    // todo 多线程情况下会出现问题
    int index = 0;

    @Override
    public AviatorObject variadicCall(Map<String, Object> env, AviatorObject... args) {
        int length = args.length;
        if (length == 0) {
            throw new RuntimeException("参数数量必须大于0");
        }
        AviatorString aviatorString = new AviatorString(String.valueOf(args[index].getValue(env)));
        index++;
        if (index > length - 1) {
            index = 0;
        }

        return aviatorString;
    }

    @Override
    public String getName() {
        return "seqEle";
    }
}
